/*
 * Description: performance event dispatcher
 */
#ifndef PERF_EVENT_DISPATCHER_H
#define PERF_EVENT_DISPATCHER_H
#include <Windows.h>
#include "singleton.h"
#include <mutex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "performance/perf_constants.h"
#include "performance/preload/process_preload_entrance.h"

namespace PERF {
class PerfEventDispatcher {
public:
    PerfEventDispatcher();
    ~PerfEventDispatcher();
    void OnProcessStart(const std::string &name, const std::string &path, const DWORD processId);
    void OnProcessEnd(const DWORD processId);
    void CheckUserLogon();

private:
    void OnUserLogon();
    std::unordered_map<DWORD, std::string> pidToPname{};
    std::unordered_map<std::string, std::unordered_set<DWORD>> pnameToPids{};
    const std::unordered_set<std::string> PROCESS_PRELOAD_WHITELIST = { PNAME_WORD, PNAME_POWERPOINT };
    std::mutex preloadMutex;
};

#define PERF_EVENT_DISPATCHER SingletonNew<PERF::PerfEventDispatcher>::GetInstance()

}  // namespace PERF
#endif